package pri.hillchen.std.consurrent.util;

import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;

/**
 * Created by hillchen on 2018/2/10.
 * 请求连接池配置类al
 */
public class PoolingHttpClientConfig {
    /**
     * 协议socket连接工厂注册器
     */
    private RegistryBuilder<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory> create();
    /**
     * 连接池最大请求连接数
     */
    private int maxTot;
    /**
     * 连接池每一路由(同一请求处理服务器)最大请求连接数
     */
    private int maxPerRouter;

    public PoolingHttpClientConfig(int maxTot, int maxPerRouter) {
        this.maxTot = maxTot;
        this.maxPerRouter = maxPerRouter;
    }

    /**
     * 连接协议id,如http、https
     * @param protocolId
     * @param connectionSocketFactory
     * @return
     */
    public PoolingHttpClientConfig registryConnectionSocketFactory(String protocolId,ConnectionSocketFactory connectionSocketFactory){
        socketFactoryRegistry.register(protocolId, connectionSocketFactory);
        return this;
    }
}
